package com.nbsaas.boot.no.ext.resource;

import com.nbsaas.boot.no.api.apis.NoSequenceApi;
import com.nbsaas.boot.no.ext.apis.NoSequenceExtApi;
import com.nbsaas.boot.no.rest.generator.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class NoSequenceExtResource implements NoSequenceExtApi {

    @Resource
    private NoSequenceApi noSequenceApi;

    @Transactional
    @Override
    public String generate(String key) {
        CompositeGenerator generator = new CompositeGenerator(
                new KeyGenerator(key),
                new DateGenerator("yyyyMMdd"),
                new RandomGenerator(4),
                new StepGenerator(key,noSequenceApi,6)
        );
        return generator.generate();
    }

    @Transactional
    @Override
    public String simple(String key, int length) {
        CompositeGenerator generator = new CompositeGenerator(
                new KeyGenerator(key),
                new StepGenerator(key,noSequenceApi,length)
        );
        return generator.generate();
    }
}
